<!DOCTYPE html>
<html lang="en">
<head>
    <title>医院门诊系统</title>
    <!-- 避免中文乱码 -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Bootstrap -->
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <!-- 引入 toastr -->
    <script src="../../toastr/toastr.js"></script>
    <link rel="stylesheet" href="../../toastr/toastr.css">
</head>
<body>
<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
    <ul class="navbar-nav">
        <li class="nav-item active">
            <a class="nav-link" href="/tohome" style="font-size:20px">我的病人</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="/case/tocase" style="font-size:20px">病例库</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="/case/toaddcase" style="font-size:20px">录入病例</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="/prescribe/toprescribe" style="font-size:20px">开药记录</a>
        </li>
    </ul>
</nav>
<script type="text/javascript">
    $(document).ready(function () {
        toastr.options.positionClass = 'toast-bottom-center';
        $(function () {
            //toregister传来的docto_id在这获取

            $.ajax({
                type: "post",
                datatype: "json",
                url: "/showregister",
                contentType: "application/json;charset=UTF-8",
                // 测试默认 doctor_id 是 101 ,但真实id已经从后台seesion获得
                data: JSON.stringify({doctor_id: "101"}),//传doctor_id到后台/showregister返回其患者信息
                success: function (result) {
                    console.log(result);
                    $.each(result, function (index, res) {
                        var id = $("<td></td>").append(res.id);
                        var name = $("<td></td>").append(res.name);
                        var register_type = $("<td></td>").append(res.register_type);
                        var time = $("<td></td>").append(res.time);
                        var url = $("<td></td>").append("<button class='btn btn-primary' id='delete"+index+"'>接诊</button>");//id加上索引循环绑定点击事件
                        var tr = $("<tr></tr>").append(id).append(name).append(register_type)
                            .append(time).append(url);
                        $("table tbody").append(tr);
                        $("#delete"+index+"").click(function () {
                            var id1 = res.id;
                            $(this).closest('tr').remove();
                            $.ajax({
                                url: "/updatebyid",
                                data: JSON.stringify({id: id1}),
                                contentType: "application/json;charset=UTF-8",
                                type: "POST",
                                success: function (flag) {
                                    if (flag > 0) {
                                        toastr.success("接诊成功");
                                    } else {
                                        toastr.error("接诊失败");
                                    }
                                }
                            })
                        })
                    })
                }
            })
        })
    })
</script>
<form class="m-3">
    <!-- 表格 -->
    <div class="panel-footer" style="height: 490px;overflow: auto;">
    <div class="form-group">
        <table class="table table-hover">
            <thead class="thead-light">
            <tr>
                <th>挂号编号</th>
                <th>挂号人</th>
                <th>挂号类型</th>
                <th>时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <!-- 显示所有病例 -->
            <tbody id="allregister">
            </tbody>
        </table>
    </div>
    </div>
</form>
</body>
</html>